<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Video extends CI_Controller {

	public function index(){
	   $this->load->model('Videos', null, true);
       $data['Videos'] = $this->Videos->getList();
		$this->load->view('video/index', $data);
	}

    /**
     * Action add
     * @author tien.nguyen
     */
    public function add(){
        $data = array();
        $this->load->model('Videos', null, true);
        
        //add product
        if($this->input->post()){
            $data = $this->input->post();
            if($this->Videos->add($data)){
                redirect(base_url().'video.html');
            }
            $data['Video'] = $data;
        }        
        $this->load->view('video/add', $data);   
    }
    
    /**
     * Delete product
     * @author tien.nguyen
     */
    public function delete($videoId){
        $this->load->model('Videos', null, true);
        if($this->Videos->delete($videoId)){
            redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : base_url().'video.html' );
        }
    }
    
    /**
     * edit save config id
     * @author tien.nguyen
     */
    public function edit($videoId){
        $res = false;
        $this->load->model('Videos', null, true);
        
        if($this->input->post()){
            $data = $this->input->post();             
            if($this->Videos->edit($data, $videoId)){
                redirect(base_url().'video.html');          
            }    
        }
        
        $data['Video'] = $this->Videos->getVideo($videoId);
        $this->load->view('video/edit', $data);       
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */